package veterinaria.servlet.historial;

import java.io.IOException;
import java.sql.ResultSet;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import veterinaria.excepcion.DAOExcepcion;
import veterinaria.modelo.Comprobante;
import veterinaria.modelo.Dueno;
import veterinaria.modelo.Medicamento;
import veterinaria.negocio.Funciones;
import veterinaria.negocio.GestionDueno;
import veterinaria.negocio.GestionHistorial;
import veterinaria.negocio.GestionMedicamentos;

/**
 * Servlet implementation class HistorialBuscarServlet
 */
@WebServlet("/HistorialBuscarServlet")
public class HistorialBuscarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HistorialBuscarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		Funciones F = new Funciones();
		
		int comprobante=0;
		
		if (request.getParameter("comprobante")!= null){
		if(F.isInteger(request.getParameter("comprobante")))
		 comprobante = Integer.parseInt(request.getParameter("comprobante"));
		}
		
		String cliente = request.getParameter("cliente");

		String f1 = request.getParameter("f1");

		String f2 = request.getParameter("f2");

		
		GestionHistorial negocio = new GestionHistorial();
		//String nombreCompleto = request.getParameter("nombreCompleto");

		try {
			Collection <Comprobante> lista = negocio.buscar(comprobante,cliente,f1,f2);

			request.setAttribute("comprobantes", lista);
			RequestDispatcher rd = request
					.getRequestDispatcher("comprobante_historial.jsp");
			rd.forward(request, response);

		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		
	}

}
